import React from "react";
import {Input, message} from 'antd';
import {_login} from "../../utils/apiList";
import './index.css';


class Login extends React.Component {
    constructor(props) {
        super(props);
        this.state = {loginParam: '', pwd: ''};
    }

    componentDidMount() {

    }

    loginToSystem = () => {
        const {loginParam, pwd} = this.state;
        _login({loginParam, pwd}).then((res) => {
            if (res.data.success) {
                this.props.history.push('/tianyi/overview');
                window.localStorage.setItem('menuSelect', '1');
                window.localStorage.setItem('menuOpen', '1');
                message.success(<b>欢迎回来，{res.data.data.userName ? res.data.data.userName : 'UNKNOWN'}~</b>, 3);
            } else {
                message.error(<b>{res.data.msg}</b>, 3);
            }
        }).catch(error => {
            message.error(<b>请求失败！</b>, 3);
        });
    };

    render() {
        const {loginParam, pwd} = this.state;
        return (
            <div className="body-box">
                <div className="login-box">
                    <h2>天宜服装租赁</h2>
                    <form>
                        <div className="user-box">
                            <Input placeholder="用户名" value={loginParam} onChange={(e) => {
                                this.setState({loginParam: e.target.value})
                            }}/>
                        </div>
                        <div className="user-box">
                            <Input.Password placeholder="密码" value={pwd} onChange={(e) => {
                                this.setState({pwd: e.target.value})
                            }}/>
                        </div>
                        <div onClick={() => this.loginToSystem()}>
                            <a><span/><span/><span/><span/>登录</a>
                        </div>
                    </form>
                </div>
            </div>
        );
    }
}

export default Login;